**Curtis RESTAT
**Table 3 Panel B regressions
**Change to directory where data and code were downloaded
**cd 
*ssc install estout

clear all
set matsize 9000
set maxvar 9000

use cbp_cty_table3,clear

do datacleancty2_table3.do


rename state stateabb
rename fipstate state
so state year
merge m:1 state year using stfueldata09_table3
keep if _merge==3
drop _merge

drop if year==2009
gen coalxenint=percoalxcoalprice*enint
gen oilxenint=peroilxoilprice*enint
gen natgasxenint=pernatgasxnatgasprice*enint

mac def fuels "coalxenint oilxenint natgasxenint"

replace trend=year-1997

qui tab naics,gen(ind)
forvalues i = 1(1)21 {
  qui replace ind`i'= ind`i'*trend
 }
forvalues i = 1(1)21 {
  qui rename ind`i' indtrend`i'
 }
 
qui tab state,gen(STdum)
foreach x of varlist STdum1-STdum49 {
qui gen trend`x'=`x'*trend
}

so ctyind year
gen empweight2=emp_imp if year==1998
bysort ctyind:carryforward empweight2,replace

qui tab year,gen(y)
drop if emp==.
gen NBPstr="NBP" if NBP==1
replace NBPstr="west" if NBPstr==""
gen NBPind=NBPstr+naics

drop if inlist(state,"38","27","19","55","23","33","50")
drop if inlist(state,"26","01") & NBP==0

*Column 1
qui eststo: qui areg  lemp_imp postxNBPxint postxNBP postxint intxNBP  y1-y11[aweight=empweight2], abs(ctyind) rob cluster(NBPind)
*Column 2
qui eststo: qui areg  lemp_imp postxNBPxint postxNBP postxint intxNBP  y1-y11 indtrend* trendSTdum* [aweight=empweight2], abs(ctyind) rob cluster(NBPind)

qui tab yearind,gen(yi)
*Column 3
qui eststo: qui areg  lemp_imp postxNBPxint postxNBP postxint intxNBP yi* trendSTdum* [aweight=empweight2], abs(ctyind) rob cluster(NBPind)
		* E/W trends
		forvalues i = 1(1)21 {
		  qui gen eindtrend`i' = indtrend`i'*NBP
		 }
		forvalues i = 1(1)21 {
		  qui gen windtrend`i' = indtrend`i'*((NBP-1)^2)
		 }
*Column 4
qui eststo: qui areg  lemp_imp postxNBPxint postxNBP postxint intxNBP windtrend* eindtrend* y1-y11 [aweight=empweight2], abs(ctyind) rob cluster(NBPind)
*Column 5
qui eststo: qui areg  lemp_imp postxNBPxint postxNBP postxint intxNBP windtrend* eindtrend* yi* trendSTdum* [aweight=empweight2], abs(ctyind) rob cluster(NBPind)
*Column 6
qui eststo: qui areg  lemp_imp postxNBPxint postxNBP postxint intxNBP windtrend* eindtrend* y1-y11 indtrend* trendSTdum* [aweight=empweight2], abs(ctyind) rob cluster(NBPind)

outreg2 [est1 est2 est3 est4 est5 est6] using "table3b.rtf",keep(postxNBPxint postxNBP) nocons replace
